package com.venta.autopartes.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.venta.autopartes.car.Color;
import com.venta.autopartes.car.PaymentMethod;
import com.venta.autopartes.user.Question;

public class UtilitiesDAO extends BaseDAO{
	private static final String SELECT_COLORS="SELECT venau_colors_catalog_id AS ID, venau_colors_catalog_name AS NAME, venau_colors_catalog_hexadecimal AS HEXADECIMAL FROM SGDLS_T_colors_catalog ORDER BY venau_colors_catalog_name ";
	private static final String SELECT_QUESTIONS="SELECT venau_questions_id AS ID, venau_questions_question AS QUESTION FROM SGDLS_T_questions ORDER BY venau_questions_question";
	
	public static List<Color> getColorsList(){
		List<Color> colorList=new ArrayList<Color>();

		connection = com.venta.autopartes.utils.Connection.getConnection();
		try {
			preparedStatement = connection.prepareStatement(SELECT_COLORS);
			resultSet = preparedStatement.executeQuery();

			while (resultSet.next()) {
				Color color = new Color(resultSet.getInt("ID"), resultSet.getString("NAME"),resultSet.getString("HEXADECIMAL"));
				colorList.add(color);
			}

		} catch (SQLException sqlException) {
			System.out.println("(Class)UtilitiesDAO - (ErrorType)sqlException");
			sqlException.printStackTrace();
			try {
				connection.rollback();
			} catch (Exception exception) {
				System.out.println("(Class)UtilitiesDAO - (ErrorType)exception");
				exception.printStackTrace();
			}
		}finally{
			closeConnection();
		}

		return colorList;
	}
	
	public static List<Question> getQuestionsList(){
		List<Question> questionsList=new ArrayList<Question>();

		connection = com.venta.autopartes.utils.Connection.getConnection();
		try {
			preparedStatement = connection.prepareStatement(SELECT_QUESTIONS);
			resultSet = preparedStatement.executeQuery();

			while (resultSet.next()) {
				Question question = new Question(resultSet.getInt("ID"), resultSet.getString("QUESTION"));
				questionsList.add(question);
			}

		} catch (SQLException sqlException) {
			System.out.println("(Class)UtilitiesDAO - (ErrorType)sqlException");
			sqlException.printStackTrace();
			try {
				connection.rollback();
			} catch (Exception exception) {
				System.out.println("(Class)UtilitiesDAO - (ErrorType)exception");
				exception.printStackTrace();
			}
		}finally{
			closeConnection();
		}

		return questionsList;
	}
		
}
